package com.wst.log4j2;

import com.wst.utils.PropertiesReader;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.Configurator;

import java.io.*;

public class SimpleXmiLog4j {

    public static void main(String[] args) {
        InputStream inStream = null;
        BufferedInputStream in = null;
        try{
            //TODO 注意该路基在每台电脑上面可能不一样！
//        File file = new File("D:\\ideaWorkSpace\\spring\\src\\main\\resources\\log4j\\simple-log4j.xml");
//        try {
            inStream = SimpleXmiLog4j.class.getClassLoader().getResourceAsStream("log4j/simple-log4j.xml");
            in = new BufferedInputStream(inStream);
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
            final ConfigurationSource source = new ConfigurationSource(in);
            Configurator.initialize(null, source);

            Logger logger = LogManager.getLogger("myLogger");
            logger.trace("trace message");
            logger.debug("debug message");
            logger.info("info message");
            logger.warn("warn message");
            logger.error("error message");
            logger.fatal("fatal message");
        } catch (IOException e){
            e.printStackTrace();
        }finally {
            if(in != null){
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
